<?php

namespace JLPay\Services;

use JLPay\Services\BaseService;
use JLPay\Models\Merchant\MerchantIncomingAddRequest;
use JLPay\Models\Merchant\MerchantIncomingAddResponse;
use JLPay\Models\Merchant\MerchantIncomingModifyRequest;
use JLPay\Models\Merchant\MerchantIncomingModifyResponse;
use JLPay\Models\Merchant\RealnameQueryRequest;
use JLPay\Models\Merchant\RealnameQueryResponse;
use JLPay\Models\Merchant\MerchantOrderQueryRequest;
use JLPay\Models\Merchant\MerchantOrderQueryResponse;
use JLPay\Models\Merchant\MerchantOrderCancelRequest;
use JLPay\Models\Merchant\MerchantOrderCancelResponse;

/**
 * 商户服务类
 */
class MerchantService extends BaseService
{
    /**
     * 获取API URL
     *
     * @param string $requestClass 请求类名
     * @param string|null $apiPath 接口路径
     * @return string 完整的API URL
     */
    public function getApiUrl(string $requestClass, ?string $apiPath = null): string
    {
        $baseUrl = $this->config->getUrl();

        if ($apiPath) {
            return $baseUrl . $apiPath;
        }

        // 使用请求类中定义的API_URL常量
        if (defined($requestClass . '::API_URL')) {
            $apiUrl = constant($requestClass . '::API_URL');
            return $baseUrl . $apiUrl;
        }

        // 如果没有定义API_URL，使用默认路径
        return $baseUrl . '/open/merch/access';
    }

    /**
     * 商户进件接口
     *
     * @param MerchantIncomingAddRequest $request 请求对象
     * @return MerchantIncomingAddResponse 响应对象
     */
    public function merchantIncomingAdd(MerchantIncomingAddRequest $request): MerchantIncomingAddResponse
    {
        return $this->post($request, MerchantIncomingAddResponse::class);
    }

    /**
     * 进件修改接口
     *
     * @param MerchantIncomingModifyRequest $request 请求对象
     * @return MerchantIncomingModifyResponse 响应对象
     */
    public function merchantIncomingModify(MerchantIncomingModifyRequest $request): MerchantIncomingModifyResponse
    {
        return $this->post($request, MerchantIncomingModifyResponse::class);
    }

    /**
     * 微信支付宝认证查询接口
     *
     * @param RealnameQueryRequest $request 请求对象
     * @return RealnameQueryResponse 响应对象
     */
    public function realnameQuery(RealnameQueryRequest $request): RealnameQueryResponse
    {
        return $this->post($request, RealnameQueryResponse::class);
    }

    /**
     * 商户申请单查询接口
     *
     * @param MerchantOrderQueryRequest $request 请求对象
     * @return MerchantOrderQueryResponse 响应对象
     */
    public function merchantOrderQuery(MerchantOrderQueryRequest $request): MerchantOrderQueryResponse
    {
        return $this->post($request, MerchantOrderQueryResponse::class);
    }

    /**
     * 商户申请单作废接口
     *
     * @param MerchantOrderCancelRequest $request 请求对象
     * @return MerchantOrderCancelResponse 响应对象
     */
    public function merchantOrderCancel(MerchantOrderCancelRequest $request): MerchantOrderCancelResponse
    {
        return $this->post($request, MerchantOrderCancelResponse::class);
    }
} 